﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;

namespace PhoneApp6
{
    public partial class MainPage : PhoneApplicationPage
    {

        // 构造函数
        public MainPage()
        {
            InitializeComponent();
            webBrowser1.Source = new Uri("http://vip.xunlei.com/login/", UriKind.Absolute);
           
           
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Page1.xaml?flstr=", UriKind.Relative));
            
        }

      

        private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            Uri uorg3 = e.Uri;
            if (uorg3 == new Uri("http://vip.xunlei.com", UriKind.Absolute))
            {
                App.cc = new CookieContainer();

                CookieContainer cc = App.cc;

                CookieCollection ck = new CookieCollection();
                ck = webBrowser1.GetCookies();
                App.cc.Add(new Uri("http://vip.xunlei.com"), ck);
                //cc.Add(new Uri("xunlei.com"),ck);
                foreach (Cookie c in ck)
                {
                    if (c.Name == "sessionid")
                    {
                        // tx1.Text += c.Name.ToString();
                        IsolatedStorageSettings.ApplicationSettings["sessionid"] = c.Value.ToString();
                        IsolatedStorageSettings.ApplicationSettings.Save();
                    }
                    if (c.Name == "userid")
                    {
                        //  richTextBox1.AppendText(co.Value);
                        App.userid = c.Value.ToString();
                    }

                }
                NavigationService.Navigate(new Uri("/Page1.xaml?flstr=", UriKind.Relative));
            }
        }

    }
}